<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div v-for="(item, index) in list" :key="index">
        <!-- {{ item.title }} -->
        <slot name="scopeData" :item="item"></slot>
      </div>
      <!-- <van-cell v-for="item in list" :key="item" :title="item.title" /> -->
    </van-list>
  </div>
</template>

<script>
import { getAction } from "@/api/manage";
export default {
  props: {
    url: {
      typa: String,
      default: "",
    },
    queryParam: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      list: [],
      querySearch: {
        pageNo: 0,
        pageSize: 10,
        total: 0,
      },
      finished: false,
      loading: false,
    };
  },
  watch: {
    queryParam: {
      handler(val) {
        console.log(val);
        this.querySearch.pageNo = 0;
        this.onLoad();
      },
      deep: true,
    },
  },
  created() {
    console.log(12345);
  },
  methods: {
    onLoad() {
      console.log(this.queryParam);
      // this.querySearch = { ...this.queryParam, ...this.querySearch };

      // this.querySearch = Object.assign(this.queryParam, this.querySearch);
      console.log(this.querySearch);
      this.querySearch.pageNo = this.querySearch.pageNo * 1 + 1;
      var params = { ...this.queryParam, ...this.querySearch };
      getAction(this.url, params).then((res) => {
        if (res.success) {
          this.querySearch.total = res.result.total;
          if (this.querySearch.pageNo == 1) {
            this.list = res.result.records;
          } else {
            this.list = this.list.concat(res.result.records);
          }

          this.loading = false;
          if (this.list.length >= this.querySearch.total) {
            this.finished = true;
          }
        }
      });

      this.$emit("onload", true);
    },
  },
};
</script>

<style lang="scss" scoped></style>
